package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PmFaults;
import com.ruoyi.system.service.IPmFaultsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 光伏版面设备故障信息Controller
 *
 * @author ruoyi
 * @date 2024-04-23
 */
@RestController
@RequestMapping("/system/faults")
public class PmFaultsController extends BaseController {
    @Autowired
    private IPmFaultsService pmFaultsService;

    /**
     * 查询光伏版面设备故障信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:faults:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmFaults pmFaults) {
        startPage();
        List<PmFaults> list = pmFaultsService.selectPmFaultsList(pmFaults);
        return getDataTable(list);
    }

    /**
     * 导出光伏版面设备故障信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:faults:export')")
    @Log(title = "光伏版面设备故障信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmFaults pmFaults) {
        List<PmFaults> list = pmFaultsService.selectPmFaultsList(pmFaults);
        ExcelUtil<PmFaults> util = new ExcelUtil<PmFaults>(PmFaults.class);
        util.exportExcel(response, list, "光伏版面设备故障信息数据");
    }

    /**
     * 获取光伏版面设备故障信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:faults:query')")
    @GetMapping(value = "/{faultId}")
    public AjaxResult getInfo(@PathVariable("faultId") Long faultId) {
        return success(pmFaultsService.selectPmFaultsByFaultId(faultId));
    }

    /**
     * 新增光伏版面设备故障信息
     */
    @PreAuthorize("@ss.hasPermi('system:faults:add')")
    @Log(title = "光伏版面设备故障信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmFaults pmFaults) {
        return toAjax(pmFaultsService.insertPmFaults(pmFaults));
    }

    /**
     * 修改光伏版面设备故障信息
     */
    @PreAuthorize("@ss.hasPermi('system:faults:edit')")
    @Log(title = "光伏版面设备故障信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmFaults pmFaults) {
        return toAjax(pmFaultsService.updatePmFaults(pmFaults));
    }

    /**
     * 删除光伏版面设备故障信息
     */
    @PreAuthorize("@ss.hasPermi('system:faults:remove')")
    @Log(title = "光伏版面设备故障信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{faultIds}")
    public AjaxResult remove(@PathVariable Long[] faultIds) {
        return toAjax(pmFaultsService.deletePmFaultsByFaultIds(faultIds));
    }
}
